package com.xca.znb.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class NewsDBHelper extends SQLiteOpenHelper {
    private static final String DATABASE_NAME = "news.db";
    private static final int DATABASE_VERSION = 1;
    //关于账户表的创建
    public static final String TABLE_NEWS = "news";
    public static final String NEWS_ID = "id" ;
    public static final String NEWS_TYPE = "type" ;
    public static final String NEWS_TITLE = "first_title" ;
    public static final String NEWS_SECOND_TITLE = "second_title" ;
    public static final String NEWS_IMG = "img" ;
    public static final String NEWS_TEXT = "texts" ;
    public static final String NEWS_PUBLISHER = "publisher" ;
    public static final String NEWS_TIME = "time" ;

    private static final String CREATE_TABLE_NEWS = "CREATE TABLE " + TABLE_NEWS +
            "(" + NEWS_ID + " INTEGER PRIMARY KEY AUTOINCREMENT ," +
            NEWS_TYPE + " TEXT NOT NULL," +
            NEWS_TITLE + " TEXT ," +
            NEWS_SECOND_TITLE + " TEXT ," +
            NEWS_IMG + " TEXT ," +
            NEWS_TEXT + " TEXT ," +
            NEWS_PUBLISHER + " TEXT ," +
            NEWS_TIME + " TEXT )" ;

    public NewsDBHelper(@Nullable Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }


    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_TABLE_NEWS);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NEWS);
        onCreate(db);
    }
}
